﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using FSS.Core.Util;
using FSS.Core.Controls;
using FSS.BLL.Entities;
using FSS.BLL.Services;
using FSS.BLL;

namespace SalesManagement.Modules.Sales
{
    public partial class VoucherInReturnList : BasePage
    {
        public VoucherInReturnList()
            : base(SCREENS.VOUCHERINRETURNLIST)
        {

        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [DirectMethod]
        public void DocumentReady()
        {
            LoadObjectCustomer();
            LoadWarehouse();
            LoadEmployee();
        }
        [DirectMethod]
        protected void LoadObjectCustomer()
        {
            
            ObjectService objectS = ObjectService.GetInstance();
            List<ObjectEntity> lstObject = (List<ObjectEntity>)objectS.ObjectLoadCustomer();
            if (!lstObject.Equals(null))
            {
                ObjectEntity objectE = new ObjectEntity();
                objectE.ObjectId = 0;
                objectE.ObjectName = "Tất cả";
                lstObject.Insert(0, objectE);
                storeObject.DataSource = lstObject;
                storeObject.DataBind();
                cboObject.SelectedIndex = 0;
            }

        }
        [DirectMethod]
        protected void LoadWarehouse()
        {
            WareHouseService warehouseS = WareHouseService.GetInstance();
            List<WareHouseEntity> lstWarehouse = (List<WareHouseEntity>)warehouseS.LoadAll();
            if (!lstWarehouse.Equals(null))
            {
                WareHouseEntity warehouseE = new WareHouseEntity();
                warehouseE.WarehouseId = 0;
                warehouseE.WarehouseName = "Tất cả";
                lstWarehouse.Insert(0, warehouseE);
                storeWarehouse.DataSource = lstWarehouse;
                storeWarehouse.DataBind();
                cboWarehouse.SelectedIndex = 0;
            }
        }
        protected void LoadEmployee()
        {

            EmployeeService employeeS = EmployeeService.GetInstance();
            IList<EmployeeEntity> lstEmployee = employeeS.LoadAll();
            if (null != lstEmployee)
            {
                EmployeeEntity employeeE = new EmployeeEntity();
                employeeE.EmployeeId = 0;
                employeeE.EmployeeName = "Tất cả";
                lstEmployee.Insert(0, employeeE);
                this.storeEmployee.DataSource = lstEmployee;
                this.storeEmployee.DataBind();
                cboEmployee.SelectedIndex = 0; 
            }
        }
        protected void VoucherList_OnRefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            int start = int.Parse(e.Parameters["start"]);
            int limit = int.Parse(e.Parameters["limit"]);
            limit += start;

            VoucherEntity voucherE = new VoucherEntity();
            if (!string.IsNullOrEmpty(txtVoucherNo.Text))
                voucherE.VoucherNo = txtVoucherNo.Text;
            if (dfDateTo.SelectedValue != null)
                voucherE.ToDate = dfDateTo.SelectedDate;
            if (dfDateFrom.SelectedValue != null)
                voucherE.FromDate = dfDateFrom.SelectedDate;
            if (cboWarehouse.Value != null)
                voucherE.WarehouseId = Util.Obj2Int(cboWarehouse.Value);
            if (cboEmployee.Value != null)
                voucherE.EmployeeId = Util.Obj2Int(cboEmployee.Value);
            VoucherService voucherS = VoucherService.GetInstance();
            voucherE.Start = start;
            voucherE.EndNum = limit;
            voucherE.TotalRow = 0;
            IList<VoucherEntity> Resul = voucherS.TranferStockSearchData(voucherE);
            e.Total = voucherE.TotalRow;
            storeVoucherList.DataSource = Resul;
            storeVoucherList.DataBind();
        }
        protected void grdMain_OnCommand(object sender, DirectEventArgs e) { }
        public void btnAdd_Click(object sender, DirectEventArgs e)
        {
           
        }
        public void btnEdit_Click(object sender, DirectEventArgs e) { }
        public void btnDelete_Click(object sender, DirectEventArgs e) { }
        public void btnPrint_Click(object sender, DirectEventArgs e) { }
        public void btnFind_Click(object sender, DirectEventArgs e) { }
    }
}
